#!/usr/bin/python

from vateblog.model.Post import Post
from vateblog.model.Comment import Comment

from vateblog.util.MemCache import MemCache

from HandlerBase import HandlerBase


class PostHandler(HandlerBase):
    def get(self):
        pid = self.request.get('id')
        post = MemCache.get_post_by_id(long(pid))

        if post is None:
            self.error(404)
            return

        query = Comment.all().filter('post=', post).order('time')
        comments = [x for x in query]
        
        self.add_attribute('post', post)
        self.add_attribute('comments', comments)
        self.add_attribute('blog', self.get_blog_info())

        self.render('post.html')
